/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view.frontend.pdf;

import com.itextpdf.text.BadElementException;
import com.itextpdf.text.DocumentException;
import exceptionManager.ExceptionManager;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.MalformedURLException;
import java.text.DecimalFormat;
import javax.swing.JPanel;
import javax.swing.text.BadLocationException;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument;
import model.Order;
import model.OrderLine;
import view.generaldesign.DesignLayout;

/**
 *
 * @author Allan
 */
public class OrderConfirmation extends javax.swing.JFrame
{
    private int orderNumber;
    private String customerPhone;
    private Order order;
    private String workingFolder;
    /**
     * Creates new form OrderConfirmation
     */
    public OrderConfirmation(Order ordre)
    {
        workingFolder = "Ordre";
        
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        double width = screenSize.getWidth();
        double height = screenSize.getHeight();

        double yPos;
        double xPos;
        
        xPos = (width / 2) - 325;
        yPos = (height / 2) - 375;
        
        this.setUndecorated(true);
        initComponents();
        this.setBounds((int)xPos, (int)yPos, 680, 710); //(x, y, width, height)
        
        // Create order object
        order = ordre;
        
        // Set info in variables
        orderNumber = order.getId();
        customerPhone = order.getCustomerSpecified()[1].getCustomerTelephone().getNumber();
        
        // Set customer info
        lblCustomerName.setText(order.getCustomerSpecified()[1].getCustomerName().getName());
        lblCustomerAddress.setText(order.getCustomerSpecified()[1].getCustomerAddress().getStreet());
        lblCustomerZip.setText(order.getCustomerSpecified()[1].getCustomerAddress().getZipCode().toString());
        lblCustomerPhone.setText(customerPhone);
        
        // Set date and orderNo
        lblDate.setText(order.getOrder_date());
        lblInvoiceNumber.setText("" + orderNumber);
        
        if(order.getTombStone() != null)
        {
            System.out.println(order.getTombStone().getOldName().size());
            
            
            // Set info in left boxes
            if(order.getTombStone().getOldName().size() > 0) // Hvis getOldName er større end 0 er det en tilføjelse
            {
                order.getTombStone().getOldName().set(0, order.getTombStone().getOldName().get(0).trim());
                if(order.getTombStone().getOldName().get(0).length() > 0)
                {
                    lblAddition.setText("X");
                }
                else
                {
                    lblNewStone.setText("X");
                }
            }
            else // Hvis getOldName er 0 (eller mindre) er det en ny sten
            {
                lblNewStone.setText("X");
            } 

            if(order.getTombStone().isCuffin()) // Hvis isCuffin indeholder true, er det en kiste
            {
                lblContainer.setText("Kiste");
            }
            else // Hvis isCuffin indeholder false, er det en urne
            {
                lblContainer.setText("Urne");
            }

            lblPickupDate.setText(order.getPickup_date());
            lblDeliveryDate.setText(order.getDelivery_date());
            
            if(order.getTombStone().getGraveYard() != null)
            {
                lblCemetery.setText(order.getTombStone().getGraveYard().getName());
            }
            
            lblDepartment.setText(order.getTombStone().getArea());
            lblRowAndNumber.setText("Ræ. " +  order.getTombStone().getTheRow() + " Nr. " + order.getTombStone().getTheNumber());

            // Set info on font and number of names
            lblFont.setText(order.getTombStone().getFont());

            // Set first oldname in label
            lblOldName.setText(order.getTombStone().getOldName().get(0));

            // Set inscription
            try
            {
                txtInscription.setFont(DesignLayout.PDF_BOLD_10);
                StyledDocument style = txtInscription.getStyledDocument();
                SimpleAttributeSet attributes = new SimpleAttributeSet();
                StyleConstants.setAlignment(attributes, StyleConstants.ALIGN_CENTER);
                style.setParagraphAttributes(0, style.getLength(), attributes, false);

                // Inserts new names
                for(String value : order.getTombStone().getInscription())
                {
                    style.insertString(style.getLength(), value, attributes);
                }
            }
            catch(BadLocationException ex)
            {
                ExceptionManager.handleBadLocationException(ex);
            }
            catch(Exception ex)
            {
                ExceptionManager.handleException(ex);
            }
        }
        
        // Set info on paymentterms
        txtPaymentTerms.setFont(DesignLayout.PDF_PLAIN_11);
        txtPaymentTerms.setText(order.getComment());
        
         // Set invironment tax description
        lblInvironmentTax.setText("Miljøafgift " + order.getProgramValues().getEnvironment_tax() + "%");
        
        // Set OrderLines
        int i;
        i = 0;
        
        double totalBeforeTax;
        totalBeforeTax = 0;
        
        for(OrderLine value : order.getOrderLine())
        {
            JPanel panel = new OrderLinePanel(order, value, 1);
            panel.setBounds(0, 2 + (i * 14), 510, 14);
            orderlinePanel.add(panel);
            i++;
            totalBeforeTax = totalBeforeTax + (value.getAmount() * value.getUnitPrice());
        }
        
        // Set invironmenttax sum
        double invironmentTax;
        invironmentTax = order.getProgramValues().getEnvironment_tax();
        double invironmentTaxSum;
        invironmentTaxSum = (totalBeforeTax / 100) * invironmentTax;
        DecimalFormat invironmentTaxFormat = new DecimalFormat("#,##0.0#");
        lblInvironmentTaxSum.setText("" + invironmentTaxFormat.format(invironmentTaxSum));
        
        // Set subtotal
        double totalAfterInvironmentTax;
        totalAfterInvironmentTax = totalBeforeTax + invironmentTaxSum;
        DecimalFormat subtotalFormat = new DecimalFormat("#,##0.0#");
        lblSubtotal.setText("" + subtotalFormat.format(totalAfterInvironmentTax));
        
        // Set VAT
        double vat;
        vat = order.getProgramValues().getVat();
        lblVAT.setText("" + vat + "%");
        
        // Set totalSum
        double total;
        total = totalAfterInvironmentTax * (1 + (vat / 100));
        DecimalFormat totalFormat = new DecimalFormat("#,##0.0#");
        lblTotalSum.setText("" + totalFormat.format(total));
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents()
    {

        jPanel27 = new javax.swing.JPanel();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        borderPanel = new javax.swing.JPanel();
        documentPanel = new javax.swing.JPanel();
        txtInscription = new javax.swing.JTextPane();
        orderlinePanel = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        lblHeadline = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        lblCustomerName = new javax.swing.JLabel();
        lblCustomerAddress = new javax.swing.JLabel();
        lblCustomerZip = new javax.swing.JLabel();
        lblCustomerPhone = new javax.swing.JLabel();
        jLabel23 = new javax.swing.JLabel();
        lblDate = new javax.swing.JLabel();
        jLabel24 = new javax.swing.JLabel();
        lblInvoiceNumber = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        txtPaymentTerms = new javax.swing.JTextArea();
        jPanel3 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        jLabel20 = new javax.swing.JLabel();
        jLabel21 = new javax.swing.JLabel();
        jLabel22 = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        jPanel5 = new javax.swing.JPanel();
        lblInvironmentTax = new javax.swing.JLabel();
        jPanel6 = new javax.swing.JPanel();
        jPanel7 = new javax.swing.JPanel();
        lblInvironmentTaxSum = new javax.swing.JLabel();
        jPanel8 = new javax.swing.JPanel();
        lblSubtotal = new javax.swing.JLabel();
        jPanel9 = new javax.swing.JPanel();
        lblVAT = new javax.swing.JLabel();
        jPanel10 = new javax.swing.JPanel();
        lblTotalSum = new javax.swing.JLabel();
        jLabel66 = new javax.swing.JLabel();
        jLabel67 = new javax.swing.JLabel();
        jLabel68 = new javax.swing.JLabel();
        jLabel30 = new javax.swing.JLabel();
        lblFont = new javax.swing.JLabel();
        jPanel11 = new javax.swing.JPanel();
        jLabel69 = new javax.swing.JLabel();
        jPanel12 = new javax.swing.JPanel();
        lblNewStone = new javax.swing.JLabel();
        jPanel13 = new javax.swing.JPanel();
        jLabel70 = new javax.swing.JLabel();
        jPanel14 = new javax.swing.JPanel();
        lblAddition = new javax.swing.JLabel();
        jPanel15 = new javax.swing.JPanel();
        jLabel71 = new javax.swing.JLabel();
        jPanel16 = new javax.swing.JPanel();
        lblContainer = new javax.swing.JLabel();
        jPanel17 = new javax.swing.JPanel();
        jLabel101 = new javax.swing.JLabel();
        jPanel18 = new javax.swing.JPanel();
        lblPickupDate = new javax.swing.JLabel();
        jPanel19 = new javax.swing.JPanel();
        jLabel103 = new javax.swing.JLabel();
        jPanel20 = new javax.swing.JPanel();
        lblDeliveryDate = new javax.swing.JLabel();
        jPanel21 = new javax.swing.JPanel();
        jLabel104 = new javax.swing.JLabel();
        jPanel22 = new javax.swing.JPanel();
        lblCemetery = new javax.swing.JLabel();
        jPanel23 = new javax.swing.JPanel();
        jLabel72 = new javax.swing.JLabel();
        jPanel24 = new javax.swing.JPanel();
        lblDepartment = new javax.swing.JLabel();
        jPanel25 = new javax.swing.JPanel();
        jLabel76 = new javax.swing.JLabel();
        jPanel26 = new javax.swing.JPanel();
        lblRowAndNumber = new javax.swing.JLabel();
        jLabel106 = new javax.swing.JLabel();
        lblOldName = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        getContentPane().setLayout(null);

        jButton3.setText("Export PDF");
        jButton3.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                jButton3ActionPerformed(evt);
            }
        });

        jButton4.setText("Close page");
        jButton4.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                jButton4ActionPerformed(evt);
            }
        });

        jButton1.setText("Arbejdsseddel");
        jButton1.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel27Layout = new javax.swing.GroupLayout(jPanel27);
        jPanel27.setLayout(jPanel27Layout);
        jPanel27Layout.setHorizontalGroup(
            jPanel27Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel27Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel27Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel27Layout.createSequentialGroup()
                        .addGroup(jPanel27Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jButton3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButton1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(0, 19, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel27Layout.setVerticalGroup(
            jPanel27Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel27Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButton3)
                .addGap(18, 18, 18)
                .addComponent(jButton1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 601, Short.MAX_VALUE)
                .addComponent(jButton4)
                .addContainerGap())
        );

        getContentPane().add(jPanel27);
        jPanel27.setBounds(531, 0, 140, 710);

        borderPanel.setBackground(new java.awt.Color(255, 255, 255));
        borderPanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        borderPanel.setLayout(null);

        documentPanel.setBackground(new java.awt.Color(255, 255, 255));
        documentPanel.setLayout(null);

        txtInscription.setEditable(false);
        txtInscription.setBorder(null);
        txtInscription.setContentType("text/html"); // NOI18N
        txtInscription.setFont(new java.awt.Font("Lucida Sans", 0, 11)); // NOI18N
        txtInscription.setAutoscrolls(false);
        txtInscription.setFocusable(false);
        documentPanel.add(txtInscription);
        txtInscription.setBounds(200, 215, 320, 140);

        orderlinePanel.setOpaque(false);
        orderlinePanel.setLayout(null);
        documentPanel.add(orderlinePanel);
        orderlinePanel.setBounds(10, 395, 510, 175);

        jLabel6.setFont(new java.awt.Font("Lucida Sans", 1, 10)); // NOI18N
        jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel6.setText("Bejerholms Stenhuggeri v/René Bejerholm Poulsen");
        documentPanel.add(jLabel6);
        jLabel6.setBounds(230, 10, 290, 14);

        jLabel7.setFont(new java.awt.Font("Lucida Sans", 0, 10)); // NOI18N
        jLabel7.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel7.setText("Fægangen 8, 4220 Korsør, Tlf. 58 35 00 04");
        documentPanel.add(jLabel7);
        jLabel7.setBounds(230, 20, 290, 14);

        jLabel8.setFont(new java.awt.Font("Lucida Sans", 0, 10)); // NOI18N
        jLabel8.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel8.setText("Nørre Allé 1, 4400 Kalundborg, Tlf. 42 76 00 04");
        documentPanel.add(jLabel8);
        jLabel8.setBounds(230, 30, 290, 14);

        jLabel9.setFont(new java.awt.Font("Lucida Sans", 0, 10)); // NOI18N
        jLabel9.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel9.setText("Fax 58 35 00 33");
        documentPanel.add(jLabel9);
        jLabel9.setBounds(230, 40, 290, 14);

        jLabel10.setFont(new java.awt.Font("Lucida Sans", 0, 10)); // NOI18N
        jLabel10.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel10.setText("bejerholms.stenhuggeri@gmail.com");
        documentPanel.add(jLabel10);
        jLabel10.setBounds(230, 50, 290, 14);

        jLabel11.setFont(new java.awt.Font("Lucida Sans", 0, 10)); // NOI18N
        jLabel11.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel11.setText("www.bejerholm-stenhuggeri.dk");
        documentPanel.add(jLabel11);
        jLabel11.setBounds(230, 60, 290, 14);

        jLabel12.setFont(new java.awt.Font("Lucida Sans", 0, 10)); // NOI18N
        jLabel12.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel12.setText("CVR-NR: 32931898");
        documentPanel.add(jLabel12);
        jLabel12.setBounds(230, 70, 290, 14);

        jLabel13.setFont(new java.awt.Font("Lucida Sans", 1, 10)); // NOI18N
        jLabel13.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel13.setText("Nordea - Reg. nr. 2190");
        documentPanel.add(jLabel13);
        jLabel13.setBounds(230, 80, 290, 14);

        jLabel14.setFont(new java.awt.Font("Lucida Sans", 1, 10)); // NOI18N
        jLabel14.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel14.setText("Konto 0754977361");
        documentPanel.add(jLabel14);
        jLabel14.setBounds(230, 90, 290, 14);

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/images/logo_docs.png"))); // NOI18N
        documentPanel.add(jLabel1);
        jLabel1.setBounds(10, 10, 170, 80);

        lblHeadline.setFont(new java.awt.Font("Lucida Sans", 1, 24)); // NOI18N
        lblHeadline.setText("Ordrebekræftelse:");
        documentPanel.add(lblHeadline);
        lblHeadline.setBounds(10, 90, 230, 29);

        jLabel16.setFont(new java.awt.Font("Lucida Sans", 1, 12)); // NOI18N
        jLabel16.setText("Kundeinformation:");
        documentPanel.add(jLabel16);
        jLabel16.setBounds(10, 120, 120, 14);

        lblCustomerName.setFont(new java.awt.Font("Lucida Sans", 0, 12)); // NOI18N
        documentPanel.add(lblCustomerName);
        lblCustomerName.setBounds(140, 120, 180, 14);

        lblCustomerAddress.setFont(new java.awt.Font("Lucida Sans", 0, 12)); // NOI18N
        documentPanel.add(lblCustomerAddress);
        lblCustomerAddress.setBounds(140, 133, 180, 14);

        lblCustomerZip.setFont(new java.awt.Font("Lucida Sans", 0, 12)); // NOI18N
        documentPanel.add(lblCustomerZip);
        lblCustomerZip.setBounds(140, 146, 180, 14);

        lblCustomerPhone.setFont(new java.awt.Font("Lucida Sans", 0, 12)); // NOI18N
        documentPanel.add(lblCustomerPhone);
        lblCustomerPhone.setBounds(140, 159, 180, 14);

        jLabel23.setFont(new java.awt.Font("Lucida Sans", 1, 12)); // NOI18N
        jLabel23.setText("Dato:");
        documentPanel.add(jLabel23);
        jLabel23.setBounds(330, 120, 80, 14);

        lblDate.setFont(new java.awt.Font("Lucida Sans", 0, 12)); // NOI18N
        lblDate.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        documentPanel.add(lblDate);
        lblDate.setBounds(410, 120, 110, 14);

        jLabel24.setFont(new java.awt.Font("Lucida Sans", 1, 12)); // NOI18N
        jLabel24.setText("Ordrenr.:");
        documentPanel.add(jLabel24);
        jLabel24.setBounds(330, 133, 80, 14);

        lblInvoiceNumber.setFont(new java.awt.Font("Lucida Sans", 0, 12)); // NOI18N
        lblInvoiceNumber.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        documentPanel.add(lblInvoiceNumber);
        lblInvoiceNumber.setBounds(410, 133, 110, 14);

        jPanel2.setBackground(new java.awt.Color(255, 255, 255));
        jPanel2.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel2.setLayout(null);

        jLabel2.setFont(new java.awt.Font("Lucida Sans", 1, 11)); // NOI18N
        jLabel2.setText("Bemærkninger:");
        jPanel2.add(jLabel2);
        jLabel2.setBounds(10, 4, 85, 14);

        txtPaymentTerms.setEditable(false);
        txtPaymentTerms.setColumns(20);
        txtPaymentTerms.setFont(new java.awt.Font("Lucida Sans", 0, 11)); // NOI18N
        txtPaymentTerms.setLineWrap(true);
        txtPaymentTerms.setRows(2);
        txtPaymentTerms.setWrapStyleWord(true);
        txtPaymentTerms.setAutoscrolls(false);
        txtPaymentTerms.setBorder(null);
        txtPaymentTerms.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        txtPaymentTerms.setDebugGraphicsOptions(javax.swing.DebugGraphics.NONE_OPTION);
        txtPaymentTerms.setDisabledTextColor(new java.awt.Color(0, 0, 0));
        txtPaymentTerms.setFocusable(false);
        jPanel2.add(txtPaymentTerms);
        txtPaymentTerms.setBounds(97, 4, 410, 28);

        documentPanel.add(jPanel2);
        jPanel2.setBounds(10, 660, 510, 35);

        jPanel3.setBackground(new java.awt.Color(204, 204, 204));
        jPanel3.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel3.setLayout(null);

        jLabel5.setFont(new java.awt.Font("Lucida Sans", 1, 9)); // NOI18N
        jLabel5.setText("ANTAL");
        jPanel3.add(jLabel5);
        jLabel5.setBounds(10, 0, 40, 14);

        jLabel20.setFont(new java.awt.Font("Lucida Sans", 1, 9)); // NOI18N
        jLabel20.setText("BESKRIVELSE");
        jPanel3.add(jLabel20);
        jLabel20.setBounds(170, 0, 70, 14);

        jLabel21.setFont(new java.awt.Font("Lucida Sans", 1, 9)); // NOI18N
        jLabel21.setText("ENHEDSPRIS");
        jPanel3.add(jLabel21);
        jLabel21.setBounds(336, 0, 60, 14);

        jLabel22.setFont(new java.awt.Font("Lucida Sans", 1, 9)); // NOI18N
        jLabel22.setText("BELØB");
        jPanel3.add(jLabel22);
        jLabel22.setBounds(440, 0, 40, 14);

        documentPanel.add(jPanel3);
        jPanel3.setBounds(10, 380, 510, 15);

        jPanel4.setBackground(new java.awt.Color(255, 255, 255));
        jPanel4.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel4.setLayout(null);
        documentPanel.add(jPanel4);
        jPanel4.setBounds(10, 390, 60, 200);

        jPanel5.setBackground(new java.awt.Color(255, 255, 255));
        jPanel5.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel5.setLayout(null);

        lblInvironmentTax.setFont(new java.awt.Font("Lucida Sans", 0, 10)); // NOI18N
        jPanel5.add(lblInvironmentTax);
        lblInvironmentTax.setBounds(12, 183, 260, 14);

        documentPanel.add(jPanel5);
        jPanel5.setBounds(60, 390, 280, 200);

        jPanel6.setBackground(new java.awt.Color(255, 255, 255));
        jPanel6.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel6.setLayout(null);
        documentPanel.add(jPanel6);
        jPanel6.setBounds(330, 390, 80, 200);

        jPanel7.setBackground(new java.awt.Color(204, 204, 204));
        jPanel7.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel7.setLayout(null);

        lblInvironmentTaxSum.setFont(new java.awt.Font("Lucida Sans", 0, 10)); // NOI18N
        lblInvironmentTaxSum.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jPanel7.add(lblInvironmentTaxSum);
        lblInvironmentTaxSum.setBounds(15, 183, 100, 14);

        documentPanel.add(jPanel7);
        jPanel7.setBounds(400, 390, 120, 200);

        jPanel8.setBackground(new java.awt.Color(255, 255, 255));
        jPanel8.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel8.setLayout(null);

        lblSubtotal.setFont(new java.awt.Font("Lucida Sans", 0, 10)); // NOI18N
        lblSubtotal.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jPanel8.add(lblSubtotal);
        lblSubtotal.setBounds(26, 15, 80, 14);

        documentPanel.add(jPanel8);
        jPanel8.setBounds(409, 580, 111, 30);

        jPanel9.setBackground(new java.awt.Color(204, 204, 204));
        jPanel9.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel9.setLayout(null);

        lblVAT.setFont(new java.awt.Font("Lucida Sans", 0, 10)); // NOI18N
        lblVAT.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jPanel9.add(lblVAT);
        lblVAT.setBounds(26, 15, 80, 14);

        documentPanel.add(jPanel9);
        jPanel9.setBounds(409, 600, 111, 30);

        jPanel10.setBackground(new java.awt.Color(255, 255, 255));
        jPanel10.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel10.setLayout(null);

        lblTotalSum.setFont(new java.awt.Font("Lucida Sans", 0, 10)); // NOI18N
        lblTotalSum.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jPanel10.add(lblTotalSum);
        lblTotalSum.setBounds(26, 15, 80, 14);

        documentPanel.add(jPanel10);
        jPanel10.setBounds(409, 620, 111, 30);

        jLabel66.setFont(new java.awt.Font("Lucida Sans", 0, 10)); // NOI18N
        jLabel66.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel66.setText("Pris");
        documentPanel.add(jLabel66);
        jLabel66.setBounds(328, 595, 80, 14);

        jLabel67.setFont(new java.awt.Font("Lucida Sans", 0, 10)); // NOI18N
        jLabel67.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel67.setText("Moms");
        documentPanel.add(jLabel67);
        jLabel67.setBounds(328, 615, 80, 14);

        jLabel68.setFont(new java.awt.Font("Lucida Sans", 0, 10)); // NOI18N
        jLabel68.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel68.setText("Total");
        documentPanel.add(jLabel68);
        jLabel68.setBounds(328, 635, 80, 14);

        jLabel30.setFont(new java.awt.Font("Lucida Sans", 1, 10)); // NOI18N
        jLabel30.setText("Skrifttype:");
        documentPanel.add(jLabel30);
        jLabel30.setBounds(310, 363, 55, 14);

        lblFont.setFont(new java.awt.Font("Lucida Sans", 0, 10)); // NOI18N
        documentPanel.add(lblFont);
        lblFont.setBounds(368, 363, 150, 14);

        jPanel11.setBackground(new java.awt.Color(255, 255, 255));
        jPanel11.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel11.setLayout(null);

        jLabel69.setFont(new java.awt.Font("Lucida Sans", 1, 10)); // NOI18N
        jLabel69.setText("Ny sten");
        jPanel11.add(jLabel69);
        jLabel69.setBounds(3, 3, 70, 14);

        documentPanel.add(jPanel11);
        jPanel11.setBounds(10, 180, 75, 20);

        jPanel12.setBackground(new java.awt.Color(255, 255, 255));
        jPanel12.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel12.setLayout(null);

        lblNewStone.setFont(new java.awt.Font("Lucida Sans", 0, 10)); // NOI18N
        lblNewStone.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jPanel12.add(lblNewStone);
        lblNewStone.setBounds(7, 3, 100, 14);

        documentPanel.add(jPanel12);
        jPanel12.setBounds(80, 180, 110, 20);

        jPanel13.setBackground(new java.awt.Color(255, 255, 255));
        jPanel13.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel13.setLayout(null);

        jLabel70.setFont(new java.awt.Font("Lucida Sans", 1, 10)); // NOI18N
        jLabel70.setText("Tilføjelse");
        jPanel13.add(jLabel70);
        jLabel70.setBounds(3, 12, 50, 14);

        documentPanel.add(jPanel13);
        jPanel13.setBounds(10, 190, 75, 30);

        jPanel14.setBackground(new java.awt.Color(255, 255, 255));
        jPanel14.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel14.setLayout(null);

        lblAddition.setFont(new java.awt.Font("Lucida Sans", 0, 10)); // NOI18N
        lblAddition.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jPanel14.add(lblAddition);
        lblAddition.setBounds(7, 12, 100, 14);

        documentPanel.add(jPanel14);
        jPanel14.setBounds(80, 190, 110, 30);

        jPanel15.setBackground(new java.awt.Color(255, 255, 255));
        jPanel15.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel15.setLayout(null);

        jLabel71.setFont(new java.awt.Font("Lucida Sans", 1, 10)); // NOI18N
        jLabel71.setText("Kiste / Urne");
        jPanel15.add(jLabel71);
        jLabel71.setBounds(3, 12, 64, 14);

        documentPanel.add(jPanel15);
        jPanel15.setBounds(10, 210, 75, 30);

        jPanel16.setBackground(new java.awt.Color(255, 255, 255));
        jPanel16.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel16.setLayout(null);

        lblContainer.setFont(new java.awt.Font("Lucida Sans", 0, 10)); // NOI18N
        lblContainer.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jPanel16.add(lblContainer);
        lblContainer.setBounds(7, 12, 100, 14);

        documentPanel.add(jPanel16);
        jPanel16.setBounds(80, 210, 110, 30);

        jPanel17.setBackground(new java.awt.Color(255, 255, 255));
        jPanel17.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel17.setLayout(null);

        jLabel101.setFont(new java.awt.Font("Lucida Sans", 1, 10)); // NOI18N
        jLabel101.setText("Afh. dato");
        jPanel17.add(jLabel101);
        jLabel101.setBounds(3, 3, 50, 14);

        documentPanel.add(jPanel17);
        jPanel17.setBounds(10, 250, 75, 20);

        jPanel18.setBackground(new java.awt.Color(255, 255, 255));
        jPanel18.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel18.setLayout(null);

        lblPickupDate.setFont(new java.awt.Font("Lucida Sans", 0, 10)); // NOI18N
        lblPickupDate.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jPanel18.add(lblPickupDate);
        lblPickupDate.setBounds(7, 3, 100, 14);

        documentPanel.add(jPanel18);
        jPanel18.setBounds(80, 250, 110, 20);

        jPanel19.setBackground(new java.awt.Color(255, 255, 255));
        jPanel19.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel19.setLayout(null);

        jLabel103.setFont(new java.awt.Font("Lucida Sans", 1, 10)); // NOI18N
        jLabel103.setText("Lev. dato");
        jPanel19.add(jLabel103);
        jLabel103.setBounds(3, 12, 50, 14);

        documentPanel.add(jPanel19);
        jPanel19.setBounds(10, 260, 75, 30);

        jPanel20.setBackground(new java.awt.Color(255, 255, 255));
        jPanel20.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel20.setLayout(null);

        lblDeliveryDate.setFont(new java.awt.Font("Lucida Sans", 0, 10)); // NOI18N
        lblDeliveryDate.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jPanel20.add(lblDeliveryDate);
        lblDeliveryDate.setBounds(7, 12, 100, 14);

        documentPanel.add(jPanel20);
        jPanel20.setBounds(80, 260, 110, 30);

        jPanel21.setBackground(new java.awt.Color(255, 255, 255));
        jPanel21.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel21.setLayout(null);

        jLabel104.setFont(new java.awt.Font("Lucida Sans", 1, 10)); // NOI18N
        jLabel104.setText("Kirkegård:");
        jPanel21.add(jLabel104);
        jLabel104.setBounds(3, 3, 60, 14);

        documentPanel.add(jPanel21);
        jPanel21.setBounds(10, 300, 75, 20);

        jPanel22.setBackground(new java.awt.Color(255, 255, 255));
        jPanel22.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel22.setLayout(null);

        lblCemetery.setFont(new java.awt.Font("Lucida Sans", 0, 10)); // NOI18N
        lblCemetery.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jPanel22.add(lblCemetery);
        lblCemetery.setBounds(7, 3, 100, 14);

        documentPanel.add(jPanel22);
        jPanel22.setBounds(80, 300, 110, 20);

        jPanel23.setBackground(new java.awt.Color(255, 255, 255));
        jPanel23.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel23.setLayout(null);

        jLabel72.setFont(new java.awt.Font("Lucida Sans", 1, 10)); // NOI18N
        jLabel72.setText("Afdeling:");
        jPanel23.add(jLabel72);
        jLabel72.setBounds(3, 12, 50, 14);

        documentPanel.add(jPanel23);
        jPanel23.setBounds(10, 310, 75, 30);

        jPanel24.setBackground(new java.awt.Color(255, 255, 255));
        jPanel24.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel24.setLayout(null);

        lblDepartment.setFont(new java.awt.Font("Lucida Sans", 0, 10)); // NOI18N
        lblDepartment.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jPanel24.add(lblDepartment);
        lblDepartment.setBounds(7, 12, 100, 14);

        documentPanel.add(jPanel24);
        jPanel24.setBounds(80, 310, 110, 30);

        jPanel25.setBackground(new java.awt.Color(255, 255, 255));
        jPanel25.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel25.setLayout(null);

        jLabel76.setFont(new java.awt.Font("Lucida Sans", 1, 10)); // NOI18N
        jLabel76.setText("Række + Nr. :");
        jPanel25.add(jLabel76);
        jLabel76.setBounds(3, 12, 70, 14);

        documentPanel.add(jPanel25);
        jPanel25.setBounds(10, 330, 75, 30);

        jPanel26.setBackground(new java.awt.Color(255, 255, 255));
        jPanel26.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel26.setLayout(null);

        lblRowAndNumber.setFont(new java.awt.Font("Lucida Sans", 0, 10)); // NOI18N
        lblRowAndNumber.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jPanel26.add(lblRowAndNumber);
        lblRowAndNumber.setBounds(7, 12, 100, 14);

        documentPanel.add(jPanel26);
        jPanel26.setBounds(80, 330, 110, 30);

        jLabel106.setFont(new java.awt.Font("Lucida Sans", 1, 12)); // NOI18N
        jLabel106.setText("Inskription");
        documentPanel.add(jLabel106);
        jLabel106.setBounds(327, 170, 69, 14);

        lblOldName.setFont(new java.awt.Font("Lucida Sans Unicode", 0, 11)); // NOI18N
        lblOldName.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        documentPanel.add(lblOldName);
        lblOldName.setBounds(200, 190, 320, 14);

        borderPanel.add(documentPanel);
        documentPanel.setBounds(2, 2, 525, 700);

        getContentPane().add(borderPanel);
        borderPanel.setBounds(0, 0, 530, 710);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton4ActionPerformed
    {//GEN-HEADEREND:event_jButton4ActionPerformed
        this.dispose();
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton3ActionPerformed
    {//GEN-HEADEREND:event_jButton3ActionPerformed
        String workingFolderPath;
        workingFolderPath = folderManager.FolderManager.checkAndCreateFolder(workingFolder);
        
        try
        {
            pdfManager.PdfManager.createPDF(workingFolderPath, customerPhone, orderNumber, documentPanel);
            

        }
        catch(BadElementException ex)
        {
            ExceptionManager.handleBadElementException(ex);
        }
        catch(DocumentException ex)
        {
            ExceptionManager.handleDocumentException(ex);
        }
        catch(FileNotFoundException ex)
        {
            ExceptionManager.handleFileNotFoundException(ex);
        }
        catch(MalformedURLException ex)
        {
            ExceptionManager.handleMalformedURLException(ex);
        }
        catch(IOException ex)
        {
            ExceptionManager.handleIOException(ex);
        }
        catch(Exception ex)
        {
            ExceptionManager.handleException(ex);
        }
        

    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton1ActionPerformed
    {//GEN-HEADEREND:event_jButton1ActionPerformed
        // Set new headline
        lblHeadline.setText("Arbejdsseddel");
        
        // Remove orderlines
        orderlinePanel.removeAll();
        orderlinePanel.updateUI();
        
        // Set orderlines without prices
        int i;
        i = 0;
        
        for(OrderLine value : order.getOrderLine())
        {
            JPanel panel = new OrderLinePanel(order, value, 2);
            panel.setBounds(0, 2 + (i * 14), 510, 14);
            orderlinePanel.add(panel);
            i++;
        }

        // Remove invironmenttax sum
        lblInvironmentTaxSum.setText("");
        
        // Remove subtotal
        lblSubtotal.setText("");
        
        // Remove VAT
        lblVAT.setText("");
        
        // Remove totalSum
        lblTotalSum.setText("");
        
        // Export to pdf in it's own folder
        workingFolder = "Arbejdsseddel";
        String workingFolderPath;
        workingFolderPath = folderManager.FolderManager.checkAndCreateFolder(workingFolder);
        
        try
        {
            pdfManager.PdfManager.createPDF(workingFolderPath, customerPhone, orderNumber, documentPanel);
        }
        catch(BadElementException ex)
        {
            ExceptionManager.handleBadElementException(ex);
        }
        catch(DocumentException ex)
        {
            ExceptionManager.handleDocumentException(ex);
        }
        catch(FileNotFoundException ex)
        {
            ExceptionManager.handleFileNotFoundException(ex);
        }
        catch(MalformedURLException ex)
        {
            ExceptionManager.handleMalformedURLException(ex);
        }
        catch(IOException ex)
        {
            ExceptionManager.handleIOException(ex);
        }
        catch(Exception ex)
        {
            ExceptionManager.handleException(ex);
        }
    }//GEN-LAST:event_jButton1ActionPerformed
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel borderPanel;
    private javax.swing.JPanel documentPanel;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel101;
    private javax.swing.JLabel jLabel103;
    private javax.swing.JLabel jLabel104;
    private javax.swing.JLabel jLabel106;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel30;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel66;
    private javax.swing.JLabel jLabel67;
    private javax.swing.JLabel jLabel68;
    private javax.swing.JLabel jLabel69;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel70;
    private javax.swing.JLabel jLabel71;
    private javax.swing.JLabel jLabel72;
    private javax.swing.JLabel jLabel76;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel10;
    private javax.swing.JPanel jPanel11;
    private javax.swing.JPanel jPanel12;
    private javax.swing.JPanel jPanel13;
    private javax.swing.JPanel jPanel14;
    private javax.swing.JPanel jPanel15;
    private javax.swing.JPanel jPanel16;
    private javax.swing.JPanel jPanel17;
    private javax.swing.JPanel jPanel18;
    private javax.swing.JPanel jPanel19;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel20;
    private javax.swing.JPanel jPanel21;
    private javax.swing.JPanel jPanel22;
    private javax.swing.JPanel jPanel23;
    private javax.swing.JPanel jPanel24;
    private javax.swing.JPanel jPanel25;
    private javax.swing.JPanel jPanel26;
    private javax.swing.JPanel jPanel27;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JLabel lblAddition;
    private javax.swing.JLabel lblCemetery;
    private javax.swing.JLabel lblContainer;
    private javax.swing.JLabel lblCustomerAddress;
    private javax.swing.JLabel lblCustomerName;
    private javax.swing.JLabel lblCustomerPhone;
    private javax.swing.JLabel lblCustomerZip;
    private javax.swing.JLabel lblDate;
    private javax.swing.JLabel lblDeliveryDate;
    private javax.swing.JLabel lblDepartment;
    private javax.swing.JLabel lblFont;
    private javax.swing.JLabel lblHeadline;
    private javax.swing.JLabel lblInvironmentTax;
    private javax.swing.JLabel lblInvironmentTaxSum;
    private javax.swing.JLabel lblInvoiceNumber;
    private javax.swing.JLabel lblNewStone;
    private javax.swing.JLabel lblOldName;
    private javax.swing.JLabel lblPickupDate;
    private javax.swing.JLabel lblRowAndNumber;
    private javax.swing.JLabel lblSubtotal;
    private javax.swing.JLabel lblTotalSum;
    private javax.swing.JLabel lblVAT;
    private javax.swing.JPanel orderlinePanel;
    private javax.swing.JTextPane txtInscription;
    private javax.swing.JTextArea txtPaymentTerms;
    // End of variables declaration//GEN-END:variables
}
